{extend name="common/application" /}
{block name="title"}<title id="title">购物车</title>{/block}
{block name="css"}

		<link rel="stylesheet" type="text/css" href="_CSS_/shopping_cart.css">
		<!--[if lt IE 9]>
	<script src="http://www.ijquery.cn/js/html5shiv.js"></script>
	<![endif]-->
		<style>
		.menuList{width: 250px;height: 532px;border-radius: 5px;}
		.menuList .activeMenu{color: #FFFFFF !important;background: #3377C1 !important;}
		.menuItem{width: 190px;height: 54px;display:block;line-height: 54px;
		background: #FFFFFF;font-size: 18px;color: #666666;padding-left: 60px;}	
		.menuContent{width: 930px;background: #FFFFFF;min-height: 660px;}
		.menuCon{padding: 30px;}
		.menuCon:hover{border-bottom:1px solid #E3E3E3;}
		.menuCon:hover .menuTitle{color: #3377C1;}
		.menuTitle{font-size: 20px;color: #333333;}
		.menuText{font-size: 14px;color: #666666;line-height: 20px;margin: 20px 0 40px 0;}
		.publishTime{font-size: 12px;color: #B7B7B7;}
		.title {
			font-size: 22px;
			color: #333333;
			display: inline-block;
			float: right;
			line-height: 68px;
			margin-left: 13px;
		}
		.main{min-height:600px;}
		
		</style>
{/block}
{block name="navbar"}{include file="/common/navbar" /}{/block}

{block name="content"}
			<!-- 主体内容 -->
			<div class="main">
				<div class="mainBody normalBox clearfix hide">
					<div class="cart-main">

						<div class="cart-table-th">
							<div class="cart-wp">
								<div class="cart-th th-chk">
									<div class="select-all">
									    <div class="cart-checkbox">
									        <input class="J_CheckBoxShop" id="J_SelectAllCbx1" type="checkbox" name="select-all" value="true">
									        <label for="J_SelectAllCbx1">勾选购物车内所有商品</label>
									    </div>
									 &nbsp;&nbsp;全选
									</div>
								</div>
								<div class="cart-th th-item">
									<div class="td-inner">商品信息</div>
								</div>
								<div class="cart-th th-type">
									<div class="td-inner">&nbsp;</div>
								</div>
								<div class="cart-th th-price">
									<div class="td-inner">价格</div>
								</div>
								<div class="cart-th th-op">
									<div class="td-inner">操作</div>
								</div>
							</div>
						</div>
						<div class="cart-box">

						</div>
					</div>
				    <div class="cart-table-th cart-table-foot">
						<div class="cart-wp">
							<div class="cart-th th-chk">
								<div class="select-all">
								    <div class="cart-checkbox">
								        <input class="J_CheckBoxShop" id="J_SelectAllCbx1" type="checkbox" name="select-all" value="true">
								        <label for="J_SelectAllCbx1">勾选购物车内所有商品</label>
								    </div>
								 &nbsp;&nbsp;全选
								</div>
							</div>
							<div class="cart-th th-item">
							    <a href="javascript:;" onclick="del_all(this)" style="padding-left: 40px;padding-right: 10px;" class="J_Del J_MakePoint">删除</a>
					 			<a title="移入收藏夹" onclick="fav_all(this)" class="btn-fav J_Fav J_MakePoint"  href="#">移入收藏夹</a>                        
							</div>
							<div class="cart-th th-type" style="width:343px;">
								<div class="td-inner">&nbsp;</div>
							</div>
							<div class="cart-th th-num">
								已选择商品<span>0</span> 件
							</div>
							<div class="cart-th th-all">
								<p>合计(不含服务费):</p>
							</div>
							<div class="cart-th th-allprice">
								<p><span>￥0.00</span></p>
							</div>
							<div class="cart-th th-balance">
								 <a href="#">结算</a>
							</div>
						</div>
					</div>	
					<div class="courseMenu">							
						<div class="courseSelect normalBox">
							<ul>
								<li class="selected">
									<a class="selectType" href="javascript:;">猜你喜欢的</a>
								</li>
								<li>
									<a class="selectType" href="javascript:;">最近收藏的</a>
								</li>
								<li>
									<a class="selectType" href="javascript:;">最近浏览的</a>
								</li>
							</ul>
						</div>
						<div class="conBody">

						</div>
					</div>
				</div>
			</div>


{/block}

{block name="js"}
		<!-- 脚本引入 -->

		<script src="_P_/layer/layer.js"></script>
		<script type="text/javascript">
			$('.title').html('购物车');
		$(function(){
			cart_list();
			hot_view();
		    var h1=$(".cart-table-foot").offset().top;
		    h2=$(window).height();
		    h=(h1+40)-h2;
		    $(window).scroll(function(){
			    var this_scrollTop = $(this).scrollTop();
			    if(this_scrollTop>h){
			     /*   alert(500);*/
			        $(".cart-table-foot").removeClass("fixed-bottom");
			    }else{
			       $(".cart-table-foot").addClass("fixed-bottom"); 
			    }
			});

			//checkbox选择效果
			/*$(".cart-checkbox label").on("click",function(){
				if($(this).parent(".cart-checkbox").hasClass("cart-checkboxed")){
                    $(this).prev().attr('checked',false);
                    $(this).parent(".cart-checkbox").removeClass("cart-checkboxed");
                } else {
                    $(this).prev().attr('checked',true);
                    $(this).parent(".cart-checkbox").addClass("cart-checkboxed");
                }
			});*/
			//全选
			$(".cart-table-th .cart-checkbox label").on("click",function(){
				if($(this).parent(".cart-checkbox").hasClass("cart-checkboxed")){
                   $(".cart-table-th .cart-checkbox label").prev().attr('checked',false);
                    $(".cart-table-th .cart-checkbox label").parent(".cart-checkbox").removeClass("cart-checkboxed");
                    $(".cart-box .cart-checkbox").removeClass("cart-checkboxed");
                    $(".cart-box .cart-checkbox input[type='checkbox']").attr('checked',false);

                } else {
                    $(".cart-table-th .cart-checkbox label").prev().attr('checked',true);
                    $(".cart-table-th .cart-checkbox label").parent(".cart-checkbox").addClass("cart-checkboxed");
                    $(".cart-box .cart-checkbox").addClass("cart-checkboxed");
                    $(".cart-box .cart-checkbox input[type='checkbox']").attr('checked',true);
                }
				$('.th-num').find('span').html($('.cart-box .order-content input[checked="checked"]').length);
				var price_total=0;
				$('.cart-box .order-content input[checked="checked"]').parents('ul').find('.price-now').each(function () {
					price_total=price_total+Number($(this).attr('number'));								
				});
				price_total= number_format(price_total, 2, ".", ",");
				$('.th-allprice').find('p span').html('￥'+price_total);
			});
			//2级checkbox
			$(".cart-box .shop .cart-checkbox label").on("click",function(){
				var lg1=$(".cart-box .shop-info .cart-checkbox").length;
				if($(this).parent(".cart-checkbox").hasClass("cart-checkboxed")){
					//自身移除选中状态
                    $(this).prev().attr('checked',false);
                    $(this).parent(".cart-checkbox").removeClass("cart-checkboxed");
                    //子集移除选择状态
                    $(this).parents(".order-body").find(".order-content .cart-checkbox").removeClass("cart-checkboxed");
                    $(this).parents(".order-body").find(".order-content .cart-checkbox input[type='checkbox']").attr('checked',false);
                    //总父级移除选中状态
                    $(".cart-table-th .cart-checkbox label").parent(".cart-checkbox").removeClass("cart-checkboxed");
	                $(".cart-table-th .cart-checkbox label").prev().attr('checked',false);
                } else {
                	//自身选中状态
                    $(this).prev().attr('checked',true);
                    $(this).parent(".cart-checkbox").addClass("cart-checkboxed");
                    //子集移除选择状态
                    $(this).parents(".order-body").find(".order-content .cart-checkbox").addClass("cart-checkboxed");
                    $(this).parents(".order-body").find(".order-content .cart-checkbox input[type='checkbox']").attr('checked',true);
                    var lg2=$(".cart-box .shop-info .cart-checkboxed").length;
                    //判断总父级选择状态
                    if(lg2==lg1){
	                    $(".cart-table-th .cart-checkbox label").parent(".cart-checkbox").addClass("cart-checkboxed");
	                    $(".cart-table-th .cart-checkbox label").prev().attr('checked',true);
                    }
                }
			});


		});
		//购物车列表
		function cart_list(){
			var userinfo=$.cookie('userinfo');
			if(userinfo) {
				var user_login = $.base64.decode(userinfo).split(",");
				var goods_uid = user_login[0];
				$.ajax({
					type: "get",
					url: "/index.php/api/service/cart_list",
					data: {'uid': goods_uid},
					dataType: 'jsonp',
					success: function (msg) {
						var html='';
						if (msg.code == 200) {
//							$('.th-num').find('span').html(msg.data.count);
//							$('.th-allprice').find('p span').html('￥'+msg.data.total);
							for(var i=0;i<msg.data.shop_id.length;i++){
								html+='<div style="height: auto;"><div class="clearfix order-body"><div class="shop clearfix"><div class="shop-info">';
								html+='<div class="cart-checkbox ">';
								html+='<input id="ckm1" type="checkbox" name="orders[]" value="s_606697081_1"><label for="ckm1">勾选此店铺下所有商品</label>';
								html+='</div><a href="/index.php/index/trade/center?'+msg.data.shop_id[i].s_id+'" title="" class="">'+msg.data.shop_id[i].name+'</a></div></div><div class="order-content"><div class="item-list"><div class="bundle  bundle-last ">';
								//商品循环
								for(var j=0;j<msg.data.data.length;j++){
									if(msg.data.data[j].s_id==msg.data.shop_id[i].s_id){
									var prices = number_format(msg.data.data[j].price, 2, ".", ",");
									html+='<div class="item-holder"><div class="J_ItemBody item-body clearfix item-normal  first-item">';
									html+='<ul class="item-content clearfix" num='+msg.data.data[j].id+'>';
									html+='<li class="cart-td td-chk"><div class="td-inner"><div class="cart-checkbox "><input class="J_CheckBoxItem" id="ck1" type="checkbox" name="" value=""><label for="ck1">勾选商品</label></div></div></li>';
									html+='<li class="cart-td td-item">';
									html+='<div class="td-inner"> <div class="item-pic J_ItemPic img-loaded"><a href="/index.php/index/service/service_details.html?id='+msg.data.data[j].goods_id+'" target="_blank"  class="J_MakePoint" data-point="tbcart.8.12"><img src="/Images/serviceGoods/'+msg.data.data[j].pic+'" class="itempic J_ItemImg"></a></div>';
									html+='<div class="item-info">';
									html+='<div class="item-basic-info"> <a href="/index.php/index/service/service_details.html?id='+msg.data.data[j].goods_id+'" target="_blank" title="" class="item-title J_MakePoint" data-point="tbcart.8.11">'+msg.data.data[j].goods_name+'</a></div>';
									html+='<div class="item-other-info"><div class="item-icon-list clearfix"><span>服务分类：'+msg.data.data[j].t_name+'</span></div></div></div></div></li>';
									html+='<li class="cart-td td-type"><div class="item-props item-props-can"><p class="sku-line" tabindex="0">服务类商品</p></div></li>';
									html+='<li class="cart-td td-price"><div class="td-inner"><div class="item-price price-promo-"><div class="price-content"><div class="price-line">';
									html+='<span class="price-now" number="'+ msg.data.data[j].price +'" >￥'+prices+'</span></div></div></div></div></li>';
									html+='<li class="cart-td td-op"><div class="td-inner"><a title="移入收藏夹" class="btn-fav J_Fav J_MakePoint" onclick="btn_fav(this,'+msg.data.data[j].id+')"  href="#">移入收藏夹</a>';
									html+='<a href="javascript:;"  class="J_Del J_MakePoint" onclick="del_goods(this,'+msg.data.data[j].id+')">删除</a></div></li></ul></div></div>';

									}
								}
								html+='</div></div></div></div></div>';
							}
							$('.cart-box').html(html);
							//2级checkbox
							$(".cart-box .shop .cart-checkbox label").on("click",function(){
								var lg1=$(".cart-box .shop-info .cart-checkbox").length;
								if($(this).parent(".cart-checkbox").hasClass("cart-checkboxed")){
									//自身移除选中状态
									$(this).prev().attr('checked',false);
									$(this).parent(".cart-checkbox").removeClass("cart-checkboxed");
									//子集移除选择状态
									$(this).parents(".order-body").find(".order-content .cart-checkbox").removeClass("cart-checkboxed");
									$(this).parents(".order-body").find(".order-content .cart-checkbox input[type='checkbox']").attr('checked',false);
									//总父级移除选中状态
									$(".cart-table-th .cart-checkbox label").parent(".cart-checkbox").removeClass("cart-checkboxed");
									$(".cart-table-th .cart-checkbox label").prev().attr('checked',false);

								} else {
									//自身选中状态
									$(this).prev().attr('checked',true);
									$(this).parent(".cart-checkbox").addClass("cart-checkboxed");
									//子集移除选择状态
									$(this).parents(".order-body").find(".order-content .cart-checkbox").addClass("cart-checkboxed");
									$(this).parents(".order-body").find(".order-content .cart-checkbox input[type='checkbox']").attr('checked',true);
									var lg2=$(".cart-box .shop-info .cart-checkboxed").length;
									//判断总父级选择状态
									if(lg2==lg1){
										$(".cart-table-th .cart-checkbox label").parent(".cart-checkbox").addClass("cart-checkboxed");
										$(".cart-table-th .cart-checkbox label").prev().attr('checked',true);
									}
								}
								$('.th-num').find('span').html($('.cart-box .order-content input[checked="checked"]').length);
								var price_total=0;
								$('.cart-box .order-content input[checked="checked"]').parents('ul').find('.price-now').each(function () {
									price_total=price_total+Number($(this).attr('number'));
								});
								price_total = number_format(price_total, 2, ".", ",");
								$('.th-allprice').find('p span').html('￥'+price_total);
							});
							//3级checkbox
							$(".cart-box .item-content .cart-checkbox label").on("click",function(){
								var lg1=$(".cart-box .shop-info .cart-checkbox").length;
								var lg3=$(this).parents(".item-list").find('.cart-checkbox').length;

								if($(this).parent(".cart-checkbox").hasClass("cart-checkboxed")){
									//自身移除选中状态
									$(this).prev().attr('checked',false);
									$(this).parent(".cart-checkbox").removeClass("cart-checkboxed");
									//父集移除选择状态
									$(this).parents(".order-body").find('.shop .cart-checkbox').removeClass("cart-checkboxed");
									$(this).parents(".order-body").find('.shop .cart-checkbox').prev().attr('checked',false);
									//总父级移除选中状态
									$(".cart-table-th .cart-checkbox label").parent(".cart-checkbox").removeClass("cart-checkboxed");
									$(".cart-table-th .cart-checkbox label").prev().attr('checked',false);
								} else {
									$(this).prev().attr('checked',true);
									$(this).parent(".cart-checkbox").addClass("cart-checkboxed");
									var lg4=$(this).parents(".item-list").find('.cart-checkboxed').length;
									if(lg4==lg3){
										$(this).parents(".order-body").find('.shop .cart-checkbox').addClass("cart-checkboxed");
										$(this).parents(".order-body").find('.shop .cart-checkbox').prev().attr('checked',true);
									}
									var lg2=$(".cart-box .shop-info .cart-checkboxed").length;
									if(lg2==lg1){
										$(".cart-table-th .cart-checkbox label").parent(".cart-checkbox").addClass("cart-checkboxed");
										$(".cart-table-th .cart-checkbox label").prev().attr('checked',true);
									}
								}
								$('.th-num').find('span').html($('.cart-box .order-content input[checked="checked"]').length);
								var price_total=0;
								$('.cart-box .order-content input[checked="checked"]').parents('ul').find('.price-now').each(function () {
										price_total=price_total+Number($(this).attr('number'));								
								});
								price_total= number_format(price_total, 2, ".", ",");
								$('.th-allprice').find('p span').html('￥'+price_total);
							});
							
							$('.mainBody').removeClass('hide');
						}
						if (msg.code == 1000) {
							<!--查询不出数据-->
							html+='<div class="nodatas"><img src="/static/web/images/nocart.png"/><p>抱歉，您的购物车暂无商品</p></div>';
							$('.cart-main').html(html);
							$('.cart-table-foot').hide();
							$('.mainBody').removeClass('hide');
						}

					}
				});
			}else{
				layer.msg('您还未登录！', {icon: 5});
				var html='<div class="nodatas"><img src="/static/web/images/nocart.png"/><p>抱歉，您的购物车暂无商品</p></div>';
				$('.cart-main').html(html);
				$('.cart-table-foot').hide();
			}
		}
        
        //单个商品删除
		function del_goods(obj,id){
			var html='<div class="goods-msg">';
			html+='<div class="goods-img"><img src="'+$(obj).parents('ul').find('.item-pic').find('.J_ItemImg').attr('src')+'"></div>';
			html+='<div class="goods-info"><p class="info-title">'+$(obj).parents('ul').find('.td-item').find('.item-basic-info a').html()+'</p>';
			html+='<p class="price-cl"><span>价格</span>'+$(obj).parents("ul").find('.price-now').html()+'</p>';
			html+='<p><span>类型</span>服务类商品</p>';
			html+='<p><span>服务分类</span>'+$(obj).parents("ul").find('.item-icon-list span').html().substring(5)+'</p></div>';
			html+='</div>';
			html+='<div class="btn-box"><p>确定要删除该商品吗？</p>';
			html+='<div class="btn-list"><a class="btn-n1" href="#">删除</a><a class="btn-n2" href="#">取消</a></div></div>';
			layer.open({
			  type: 1,
			  title:'删除商品',
			  skin: 'layui-layer-lan',
			  area: ['560px', '305px'], //宽高
			  content:html
			});
			$('.btn-n1').on("click",function(){
				//数据
				var lg1=$(obj).parents(".item-list").find('.cart-checkbox').length;
				$.ajax({
					type: "get",
					url: "/index.php/api/service/cart_del",
					data: {'id': id},
					dataType: 'jsonp',
					success: function (msg) {
						if(msg.code==200){
							if(lg1==1){
								$(obj).parents('.order-body').parent().empty();
							}else{
								$(obj).parents('.item-holder').empty();
							}
							layer.msg('删除成功！', {icon: 1},function(){
								$('.th-num').find('span').html($('.cart-box .order-content input[checked="checked"]').length);
								var price_total=0;
								$('.cart-box .order-content input[checked="checked"]').parents('ul').find('.price-now').each(function () {
										price_total=price_total+Number($(this).attr('number'));								
								});
								price_total= number_format(price_total, 2, ".", ",");
								$('.th-allprice').find('p span').html('￥'+price_total);
								layer.closeAll();
							});
						}
						if(msg.code==1000){
							layer.msg('删除失败！', {icon: 51});
						}
					}
				});

			});
			$('.btn-n2').on("click",function(){
				layer.close(layer.index);
			})
		};
        //单个商品移入收藏夹
		function btn_fav(obj,id){
			var html='<div class="goods-msg">';
			html+='<div class="goods-img"><img src="'+$(obj).parents('ul').find('.item-pic').find('.J_ItemImg').attr('src')+'"></div>';
			html+='<div class="goods-info"><p class="info-title">'+$(obj).parents('ul').find('.td-item').find('.item-basic-info a').html()+'</p>';
			html+='<p class="price-cl"><span>价格</span>'+$(obj).parents("ul").find('.price-now').html()+'</p>';
			html+='<p><span>类型</span>服务类商品</p>';
			html+='<p><span>服务分类</span>'+$(obj).parents("ul").find('.item-icon-list span').html().substring(5)+'</p></div>';
			html+='</div>';
			html+='<div class="btn-box"><p>确定要该商品移入收藏夹吗？</p>';
			html+='<div class="btn-list"><a class="btn-n1" href="#">确定</a><a class="btn-n2" href="#">取消</a></div></div>';
			layer.open({
			  type: 1,
			  title:'删除商品',
			  skin: 'layui-layer-lan',
			  area: ['560px', '305px'], //宽高
			  content:html
			});

			$('.btn-n1').on("click",function(){
				var userinfo=$.cookie('userinfo');
				if(userinfo) {
					var user_login = $.base64.decode(userinfo).split(",");
					var uid = user_login[0];
					var lg1 = $(obj).parents(".item-list").find('.cart-checkbox').length;
					$.ajax({
						type: "get",
						url: "/index.php/api/service/cart_collect",
						data: {'id': id, 'uid': uid},
						dataType: 'jsonp',
						success: function (msg) {
							if (msg.code == 200) {
								if (lg1 == 1) {
									$(obj).parents('.order-body').parent().empty();
								} else {
									$(obj).parents('.item-holder').empty();
								}
								layer.msg('收藏成功！', {icon: 1}, function () {
									$('.th-num').find('span').html($('.cart-box .order-content input[checked="checked"]').length);
									var price_total = 0;
									$('.cart-box .order-content input[checked="checked"]').parents('ul').find('.price-now').each(function () {
											price_total=price_total+Number($(this).attr('number'));								
									});
									price_total= number_format(price_total, 2, ".", ",");
									$('.th-allprice').find('p span').html('￥' + price_total);
									layer.closeAll();
								});
							}
							if (msg.code == 1000) {
								layer.msg('收藏失败！', {icon: 51});
							}
						}
					});
				}else{
					layer.msg('还未登录！', {icon: 51});
				}
			});
			$('.btn-n2').on("click",function(){
				layer.close(layer.index);
			})
		};
		//多个删除提醒
		function del_all(obj){
			var arrs = [];
			$('.cart-box .order-content input[checked="checked"]').parents('ul').each(function () {
				arrs.push($(this).attr('num'));
			});
			if (arrs.length == 0) {
				layer.msg('请选择删除项!', {icon: 1, time: 1000});
				return false;
			}
			var ids = arrs.join(",");
			layer.confirm('您确定要删除所有选中的商品吗？', {
			  btn: ['确定','取消'] //按钮
			}, function(){
			  //相关数据操作
				$.ajax({
					type: "get",
					url: "/index.php/api/service/cart_del",
					data: {'id': ids},
					dataType: 'jsonp',
					success: function (msg) {
						if(msg.code==200){
							$(".cart-box .shop .cart-checkbox input[type='checkbox']").each(function () {
								var lg1=$(this).parents('.order-body').find('.order-content').find('input[type="checkbox"]').length;
								var lg2=$(this).parents('.order-body').find('.order-content').find('input[checked="checked"]').length;
								if(lg1==lg2){
									$(this).parents('.order-body').parent().empty();
								}else{
									$(this).parents('.order-body').find('.order-content').find('input[checked="checked"]').each(function (index,element) {
										$(element).parents('.item-holder').empty();
									});
								}
							});
							$('.th-num').find('span').html(0);
							$('.th-allprice').find('p span').html('￥0.00');
							layer.msg('删除成功！', {icon: 1},function(){

								layer.closeAll();
							});
						}
						if(msg.code==1000){
							layer.msg('删除失败！', {icon: 51});
						}
					}
				});
			  layer.close(layer.index);
			}, function(){
			   layer.close(layer.index);
			})
	    }
         //多个移入收藏夹
	    function fav_all(obj){
			var arrs = [];
			$('.cart-box .order-content input[checked="checked"]').parents('ul').each(function () {
				arrs.push($(this).attr('num'));
			});
			if (arrs.length == 0) {
				layer.msg('请选择收藏项!', {icon: 1, time: 1000});
				return false;
			}
			var ids = arrs.join(",");
			layer.confirm('您确定要将所有选中的商品移入收藏夹吗？', {
			  btn: ['确定','取消'] //按钮
			}, function(){
				var userinfo=$.cookie('userinfo');
				if(userinfo) {
					var user_login = $.base64.decode(userinfo).split(",");
					var uid = user_login[0];
					//相关数据操作
					$.ajax({
						type: "get",
						url: "/index.php/api/service/cart_collect",
						data: {'id': ids,'uid':uid},
						dataType: 'jsonp',
						success: function (msg) {
							if (msg.code == 200) {
								$(".cart-box .shop .cart-checkbox input[type='checkbox']").each(function () {
									var lg1 = $(this).parents('.order-body').find('.order-content').find('input[type="checkbox"]').length;
									var lg2 = $(this).parents('.order-body').find('.order-content').find('input[checked="checked"]').length;
									if (lg1 == lg2) {
										$(this).parents('.order-body').parent().empty();
									} else {
										$(this).parents('.order-body').find('.order-content').find('input[checked="checked"]').each(function (index, element) {
											$(element).parents('.item-holder').empty();
										});
									}
								});
								$('.th-num').find('span').html(0);
								$('.th-allprice').find('p span').html('￥0.00');
								layer.msg('收藏成功！', {icon: 1}, function () {
									layer.closeAll();
								});
							}
							if (msg.code == 1000) {
								layer.msg('删除失败！', {icon: 51});
							}
						}
					});
				}else{
					layer.msg('还未登录！', {icon: 51});
				}
			}, function(){
			   layer.close(layer.index);
			})
	    }

	    //推荐切换
	    $('.courseSelect ul li').on('click',function(){
	    	$(".courseSelect ul li").removeClass("selected");
            $(this).addClass("selected");
			var index = $('.courseSelect ul li').index($(this));
			if(index==1){
				recent_collect();
			}else if(index==2){
				recent_view();
			}else{
				hot_view();
			}
	    });
		//最近收藏
		function recent_collect(){
			var userinfo=$.cookie('userinfo');
			//var userinfo = 1;
			if(userinfo) {
				var user_login = $.base64.decode(userinfo).split(",");
				var uid = user_login[0];
				$.ajax({
					type: "get",
					url: "/index.php/api/service/recent_collect",
					data: {'uid': uid},
					dataType: 'jsonp',
					success: function (msg) {
						if (msg.code == 200) {
							var html="";
							for (var i = 0; i < msg.data.length; i++) {
								var money = number_format(msg.data[i].price, 2, ".", ",");
								if (i == 4) {
									html += '<div class="serviceItem mr0">';
								} else {
									html += '<div class="serviceItem">';
								}
								html += '<a class="goDetails" href="/index.php/index/service/service_details.html?id=' + msg.data[i].id + '"><img src="/Images/serviceGoods/' + msg.data[i].pic + '"/></a>';
								html += '<div class="serviceCon"><span class="prices">￥' + money + '</span>';
								html += '<a class="serviceTitle moreline" limit="24" href="/index.php/index/service/service_details.html?id='+ msg.data[i].id + '">' + msg.data[i].goods_name + '</a>';
								html += '<a class="company text_overflow" href="store_details.html" title="' + msg.data[i].name + '">' + msg.data[i].name + '</a>';
								html += '<p class="volume">成交量<span class="volumeNum">' + msg.data[i].volume + '</span>笔</p>';
								html += '<p class="assess">评价<span class="assessNum">' + msg.data[i].rate + '</span>条</p></div></div>';
							}
							$('.conBody').html(html);
						}
						if (msg.code == 1000) {
							layer.msg('还未收藏！', {icon: 51});
							$('.conBody').html('<div class="serviceItem"></div>');
						}
					}
				});
			}
		}
		//猜你喜欢
		function hot_view(){
			$.ajax({
				type:"get",
				url:"/index.php/api/service/rand_goods",
				data:{'number':5,'order':'rand()'},
				dataType:'jsonp',
				success:function(msg){
					var html="";
					if(msg.code == 200){
						for(var i=0;i<msg.data.length;i++){
							var money = number_format(msg.data[i].price, 2, ".", ",");
							if(i==4){
								html+='<div class="serviceItem mr0">';
							}else{
								html+='<div class="serviceItem">';
							}
							html+='<a class="goDetails" href="/index.php/index/service/service_details.html?id='+msg.data[i].id+'"><img src="/Images/serviceGoods/'+msg.data[i].pic+'"/></a>';
							html+='<div class="serviceCon"><span class="prices">￥'+money+'</span>';
							html+='<a class="serviceTitle moreline" limit="24" href="/index.php/index/service/service_details.html?id='+msg.data[i].id+'">'+msg.data[i].goods_name+'</a>';
							html+='<a class="company text_overflow" href="store_details.html" title="'+msg.data[i].name+'">'+msg.data[i].name+'</a>';
							html+='<p class="volume">成交量<span class="volumeNum">'+msg.data[i].volume+'</span>笔</p>';
							html+='<p class="assess">评价<span class="assessNum">'+msg.data[i].rate+'</span>条</p></div></div>';
						}
						$('.conBody').html(html);
					}
				}
			});
		}
		//最近浏览
		function recent_view(){
			var recent_service=$.cookie('recent_service');
			if(recent_service){
				var service = $.base64.decode(recent_service);
				$.ajax({
					type:"get",
					url:"/index.php/api/service/recent_view",
					data:{'id':service},
					dataType:'jsonp',
					success:function(msg){
						var html="";
						if(msg.code == 200){
							for(var i=0;i<msg.data.length;i++){
								var money = number_format(msg.data[i].price, 2, ".", ",");
								if(i==4){
									html+='<div class="serviceItem mr0">';
								}else{
									html+='<div class="serviceItem">';
								}
								html+='<a class="goDetails" href="/index.php/index/service/service_details.html?id='+msg.data[i].id+'"><img src="/Images/serviceGoods/'+msg.data[i].pic+'"/></a>';
								html+='<div class="serviceCon"><span class="prices">￥'+money+'</span>';
								html+='<a class="serviceTitle moreline" limit="24" href="/index.php/index/service/service_details.html?id='+msg.data[i].id+'">'+msg.data[i].goods_name+'</a>';
								html+='<a class="company text_overflow" href="store_details.html" title="'+msg.data[i].shop_name+'">'+msg.data[i].shop_name+'</a>';
								html+='<p class="volume">成交量<span class="volumeNum">'+msg.data[i].volume+'</span>笔</p>';
								html+='<p class="assess">评价<span class="assessNum">'+msg.data[i].rate+'</span>条</p></div></div>';
							}
							$('.conBody').html(html);
						}
					}
				});
			}else{
				$('.conBody').html('<div class="serviceItem"></div>');
			}

		}
		/**结算生成订单**/
		$('.th-balance').on('click',function(){
			var userinfo=$.cookie('userinfo');
			//var userinfo = 1;
			if(userinfo) {
				var user_login = $.base64.decode(userinfo).split(",");
				var uid = user_login[0];
				var arrs = [];
				$('.cart-box .order-content input[checked="checked"]').parents('ul').each(function () {
					arrs.push($(this).attr('num'));
				});
				if (arrs.length == 0) {
					layer.msg('您还未选择商品!', {icon: 1, time: 1000});
					return false;
				}
				var ids = arrs.join(",");
				$.ajax({
					type: "get",
					url: "/index.php/api/form/order_start",
					data: {'id': ids,'uid':uid},
					dataType: 'jsonp',
					success: function (msg) {
						if (msg.code == 200) {
							layer.msg('已生成订单!', {icon: 1, time: 1000});
							$(".cart-box .shop .cart-checkbox input[type='checkbox']").each(function () {
								var lg1 = $(this).parents('.order-body').find('.order-content').find('input[type="checkbox"]').length;
								var lg2 = $(this).parents('.order-body').find('.order-content').find('input[checked="checked"]').length;
								if (lg1 == lg2) {
									//$(this).parents('.order-body').parent().empty();
									var html='<div class="nodatas"><img src="/static/web/images/nocart.png"/><p>抱歉，您的购物车暂无商品</p></div>';
									$('.cart-main').html(html);
									$('.cart-table-foot').hide();
								} else {
									$(this).parents('.order-body').find('.order-content').find('input[checked="checked"]').each(function (index, element) {
										$(element).parents('.item-holder').empty();
									});
								}
							});
							$('.th-num').find('span').html(0);
							$('.th-allprice').find('p span').html('￥0.00');
						}
						if (msg.code == 1000) {
							layer.msg('网络错误!', {icon: 5, time: 1000});
						}
					}
				});
			}else{
				layer.msg('还未的登录!', {icon: 51});
			}
		})
		</script>
{/block}